package com.cl.controller;

import com.cl.bean.User;
import com.cl.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Resource
    private UserService us;

    //登陆
    @RequestMapping("login.do")
    public String login(User user, HttpSession session){
        User login = us.login(user);
        if(login!=null){
            session.setAttribute("user",login);
            return "redirect:list.do";
        }else{
            return "redirect:index.jsp";
        }
    }

    //去注册页面
    @RequestMapping("toreg.do")
    public String toreg(){
        return "reg";
    }

    //注册
    @RequestMapping("reg.do")
    public String reg(User user){
        us.reg(user);
        return "redirect:index.jsp";
    }
}
